package com._21cn.cms.article.entity.vo;

import com._21cn.cms.article.Constants;
import com._21cn.cms.article.entity.Article;
import com._21cn.cms.article.entity.ArticlePicture;
import com._21cn.framework.utils.StringUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ListArticle
        implements Serializable
{
    private Pattern ARTICLE_URL_PATTERN = Pattern.compile("/(\\d{4})/(\\d{4})/(\\d{2})/(\\d{1,10})\\.shtml");

    private static final long serialVersionUID = -1L;
    private Integer id = 0;
    private Integer articleId = 0;
    private String articleUrl = "";
    private String articleAppUrl = "";
    private Integer articleType = Constants.ARTICLE_TYPE_COMMON;
    private String title;
    private String summary;
    private Date publishTime;
    private Integer publishStatus = Constants.PUBLISH_STATUS_NONE;
    private Integer picFlag;
    private Integer topTime = 0;
    private Date createTime = new Date();
    private Integer createUserId = 0;
    private Date modifyTime = new Date();
    private Integer modifyUserId = 0;
    private String firstPicUrl = "";

    public String getFirstPicUrl() {
        return this.firstPicUrl;
    }

    public String getFirstPicUrl(int width, int height) {
        return getFirstPicUrl("/s" + width + "x" + height + "/");
    }

    public String getFirstPicUrl(String code) {
        String firstPicUrl = getFirstPicUrl();
        if (StringUtil.isImageFile(firstPicUrl)) {
            try {
                String[] thumbAry = firstPicUrl.split("/");
                String imgSize = thumbAry[(thumbAry.length - 2)];
                firstPicUrl = firstPicUrl.replaceFirst("/" + imgSize + "/", "/" + code + "/");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return firstPicUrl;
    }

    public void setFirstPicUrl(String firstPicUrl) {
        this.firstPicUrl = firstPicUrl;
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getArticleId() {
        return this.articleId;
    }

    public void setArticleId(Integer articleId) {
        this.articleId = articleId;
    }

    public String getArticleUrl() {
        return this.articleUrl;
    }

    public void setArticleUrl(String articleUrl) {
        this.articleUrl = articleUrl;
    }

    public String getArticleAppUrl() {
        if (!StringUtil.isEmpty(this.articleUrl)) {
            Matcher matcher = this.ARTICLE_URL_PATTERN.matcher(this.articleUrl);
            if (matcher.find())
                this.articleAppUrl = this.articleUrl.replace("/a/", "/c/");
            else {
                this.articleAppUrl = this.articleUrl;
            }
        }
        return articleAppUrl;
    }

    public void setArticleAppUrl(String articleAppUrl) {
        this.articleAppUrl = articleAppUrl;
    }

    public Integer getArticleType() {
        return this.articleType;
    }

    public void setArticleType(Integer articleType) {
        this.articleType = articleType;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSummary() {
        return this.summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public Date getPublishTime() {
        return this.publishTime;
    }

    public void setPublishTime(Date publishTime) {
        this.publishTime = publishTime;
    }

    public Integer getPublishStatus() {
        return this.publishStatus;
    }

    public void setPublishStatus(Integer publishStatus) {
        this.publishStatus = publishStatus;
    }

    public Integer getPicFlag() {
        return this.picFlag;
    }

    public void setPicFlag(Integer picFlag) {
        this.picFlag = picFlag;
    }

    public Integer getTopTime() {
        return this.topTime;
    }

    public void setTopTime(Integer topTime) {
        this.topTime = topTime;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getCreateUserId() {
        return this.createUserId;
    }

    public void setCreateUserId(Integer createUserId) {
        this.createUserId = createUserId;
    }

    public Date getModifyTime() {
        return this.modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Integer getModifyUserId() {
        return this.modifyUserId;
    }

    public void setModifyUserId(Integer modifyUserId) {
        this.modifyUserId = modifyUserId;
    }

    public ListArticle initWith(Article article) {
        this.articleId = article.getId();
        this.articleType = article.getArticleType();
        this.title = article.getTitle();
        this.summary = article.getSummary();
        this.publishTime = article.getPublishTime();
        this.publishStatus = article.getPublishStatus();
        this.createTime = article.getCreateTime();
        this.createUserId = article.getCreateUserId();
        this.modifyTime = article.getModifyTime();
        this.modifyUserId = article.getModifyUserId();
        this.picFlag = article.getPicFlag();
        this.firstPicUrl = article.getFirstPicUrl();
        this.articleUrl = article.getArticleUrl();
        this.topTime = article.getTopTime();
        List list = new ArrayList();
        if ((article.getArticlePictureList() != null) && (article.getArticlePictureList().size() > 0)) {
            for (ArticlePicture articlePicture : article.getArticlePictureList()) {
                list.add(articlePicture.getPicUrl());
            }
        }
        return this;
    }
}